<?php

namespace App\Console\Commands\System\Project;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;

class ProjectErrorGuideCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'system:projectErrorGuide';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '系统错误码向导';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(): int
    {
        $this->askContent();
        return parent::SUCCESS;
    }

    public function askContent()
    {
        $this->info("请选择以下执行任务：");
        $target = $this->ask(vsprintf("%s%s%s", [
            "1、 生成项目" . PHP_EOL,
            " 2、 生成模块" . PHP_EOL,
            " 3、 生成错误码" . PHP_EOL,
        ]));

        switch ($target) {
            case 1:
                Artisan::call("system:projectGenerate", [], $this->getOutput());
                break;
            case 2:
                Artisan::call("system:projectModuleGenerate", [], $this->getOutput());
                break;
            case 3:
                Artisan::call("system:projectModuleErrorGenerate", [], $this->getOutput());
                break;
            default:
                $this->error("输入有误");
                $this->askContent();
                break;
        }
    }
}
